package com.itheima.myGenericity.test;

import java.util.Collections;
import java.util.TreeSet;

public class MyTest1 {
    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>();

        Student s1 = new Student("柳岩", 36);
        Student s2 = new Student("杨幂", 35);
        Student s3 = new Student("贾玲", 38);
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);

        System.out.println(ts);
    }
}

class Student implements Comparable<Student> {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public int compare(Student o) {

        int res = this.age - o.age;
        return res;

    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        int result = this.age - o.age;
        return result;
    }
}
